﻿namespace ExamV5.OnLineInter
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmEditForumInfo : Page
    {
        protected Button butClose;
        protected Button butDefault;
        protected Button butDel;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected int intID = 0;
        private PublicFun publicFun_0 = new PublicFun();
        protected RadioButtonList RBLIsAnony;
        protected ScriptManager SM;
        protected string strReUserCode = "";
        protected string strReUserName = "";
        protected TextBox txtAddFen;
        protected TextBox txtReFen;
        protected TextBox txtTipInfo;
        protected TextBox txtTitleName;
        protected TextBox txtTypeInfo;
        protected UpdatePanel UPPart;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            string str = "";
            str = base.Request.Form["txtUserCode"].ToString();
            base.Request.Form["txtUserName"].ToString();
            string strSql = "";
            if (this.intID != 0)
            {
                strSql = string.Concat(new object[] { "update ForumType set TypeName='", this.publicFun_0.CheckString(this.txtTitleName.Text), "',TypeInfo='", this.publicFun_0.CheckString(this.txtTypeInfo.Text), "',Manager='", str, "',TipInfo='", this.publicFun_0.CheckString(this.txtTipInfo.Text), "',IsAnony='", this.RBLIsAnony.SelectedItem.Value, "',AddFen='", this.txtAddFen.Text.Trim(), "',ReFen='", this.txtReFen.Text.Trim(), "' where ID=", this.intID });
            }
            else
            {
                strSql = "Insert into ForumType(TypeName,TypeInfo,Manager,TipInfo,IsAnony,InputUser,AddFen,ReFen) values(";
                strSql = strSql + "'" + this.publicFun_0.CheckString(this.txtTitleName.Text) + "','" + this.publicFun_0.CheckString(this.txtTypeInfo.Text) + "','" + str + "','" + this.publicFun_0.CheckString(this.txtTipInfo.Text) + "','" + this.RBLIsAnony.SelectedItem.Value + "','" + this.httpCookie_0.Value + "','" + this.txtAddFen.Text.Trim() + "','" + this.txtReFen.Text.Trim() + "')";
            }
            this.publicFun_0.ExecuteSql(strSql);
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BEditSucc", "alert('提交论坛版块操作成功！');parent.location.href='ManagForumList.aspx';window.close();", true);
        }

        protected void butDel_Click(object sender, EventArgs e)
        {
            string strSql = "";
            strSql = string.Concat(new object[] { "Delete from ForumType where ID=", this.intID, ";Delete from ForumList where TypeID=", this.intID });
            this.publicFun_0.ExecuteSql(strSql);
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BEditSucc", "alert('删除论坛版块操作成功！');parent.location.href='ManagForumList.aspx';window.close();", true);
        }

        private void method_0()
        {
            string cmdText = "select b.UserName,a.TypeName,a.TypeInfo,a.Manager,a.TipInfo,a.IsAnony,a.AddFen,a.ReFen from ForumType a,UserInfo b where a.Manager=b.UserCode and a.ID=" + this.intID;
            if ((this.ViewState["AddPower"].ToString() == "Y") && (this.ViewState["ManagPower"].ToString() == "N"))
            {
                cmdText = cmdText + " and InputUser='" + this.httpCookie_0.Value + "'";
            }
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand(cmdText, connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            try
            {
                if (reader.Read())
                {
                    this.txtTypeInfo.Text = reader["TypeInfo"].ToString();
                    this.txtTipInfo.Text = reader["TipInfo"].ToString();
                    this.txtTitleName.Text = reader["TypeName"].ToString();
                    this.RBLIsAnony.SelectedIndex = -1;
                    this.RBLIsAnony.Items.FindByValue(reader["IsAnony"].ToString()).Selected = true;
                    this.txtAddFen.Text = reader["AddFen"].ToString();
                    this.txtReFen.Text = reader["ReFen"].ToString();
                    this.strReUserName = reader["UserName"].ToString();
                    this.strReUserCode = reader["Manager"].ToString();
                }
            }
            catch
            {
            }
            finally
            {
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) && (this.httpCookie_0.Value != ""))
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.intID = Convert.ToInt32(base.Request["ID"].ToString());
                base.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---编辑论坛版块信息";
                if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                        connection.Open();
                        SqlCommand command = new SqlCommand("select AddForum,ManagForum from UserPower where UserCode='" + this.httpCookie_0.Value + "'", connection);
                        SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        if (reader.Read())
                        {
                            this.ViewState["AddPower"] = reader["AddForum"].ToString();
                            this.ViewState["ManagPower"] = reader["ManagForum"].ToString();
                        }
                        reader.Close();
                        command.Dispose();
                        connection.Close();
                        connection.Dispose();
                        if (!(this.ViewState["AddPower"].ToString() == "N") || !(this.ViewState["ManagPower"].ToString() == "N"))
                        {
                            this.butDefault.Visible = true;
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BPower", "alert('添加或管理论坛权限未开放！')", true);
                            this.butDefault.Visible = false;
                        }
                        if (this.intID != 0)
                        {
                            this.method_0();
                            this.butDel.Visible = true;
                            this.butDel.Attributes.Add("onclick", @"javascript:{if(confirm('删除版块后，论坛中的帖子也将全部清除\n\n确定删除版块信息吗？')==false) return false;}");
                        }
                        else
                        {
                            this.butDel.Visible = false;
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

